Skip to content

feat(trader): add configurable profit drawdown close#1401

Open
nn87200 wants to merge 2 commits intoNoFxAiOS:devfrom
nn87200:feature/profit-drawdown-close
Open

feat(trader): add configurable profit drawdown close#1401
nn87200 wants to merge 2 commits intoNoFxAiOS:devfrom
nn87200:feature/profit-drawdown-close

Conversation

@nn87200
Copy link

@nn87200 nn87200 commented Mar 4, 2026

📝 Description

What: Adds configurable profit drawdown close. Users can set min profit % and pullback from peak % in strategy risk control, with an enable/disable option.

Why: Allows per-strategy tuning of when positions are closed based on profit drawdown from peak, instead of fixed 5% min profit and 40% pullback.


🎯 Type of Change

  • ✨ New feature
  • 🐛 Bug fix
  • 💥 Breaking change
  • 📝 Documentation update
  • ♻️ Refactoring
  • ⚡ Performance improvement
  • ✅ Test update
  • 🔧 Build/config change

🔗 Related Issues

  • Closes #
  • Related to #

📋 Changes Made

  • store/strategy.go: Add EnableDrawdownClose, DrawdownCloseMinProfitPct, DrawdownClosePct to RiskControlConfig with defaults (5%, 40%)
  • trader/auto_trader.go: Add shouldTriggerDrawdownClose() and wire checkPositionDrawdown() to strategy config
  • trader/drawdown_test.go: Add unit tests for drawdown close logic
  • web/src/components/strategy/RiskControlEditor.tsx: Add profit drawdown close UI (enable checkbox, min profit %, pullback % inputs) with zh/en translations
  • web/src/types.ts: Add RiskControlConfig fields for drawdown close

🧪 Testing

  • Tested locally
  • Tests pass (go test ./trader -run TestShouldTriggerDrawdownClose)
  • Verified no existing functionality broke

Testing steps:

  1. Run go test -v ./trader -run TestShouldTriggerDrawdownClose → all 10 tests pass
  2. Run go test ./trader → existing tests pass
  3. Run npm test in web → 108 tests pass

✅ Checklist

Before Submitting

  • Code compiles (go build)
  • Tests pass (go test ./trader)
  • No lint errors (go fmt, go vet)
  • Documentation updated (inline comments)
  • Commits follow conventional commits
  • Branch rebased on latest dev

PR Template

  • Clear description of what and why
  • Type of change marked
  • Related issues linked (if any)
  • Testing steps documented
  • Screenshots (Risk Control panel in Strategy Studio)

📚 Additional Notes

  • Backward compatible: Defaults match previous behavior (5% min profit, 40% pullback).
  • PR size: ~264 lines (within small PR target).
  • Risk Control panel in Strategy Studio:
image

nn87200 added 2 commits March 4, 2026 23:21
- Add EnableDrawdownClose, DrawdownCloseMinProfitPct, DrawdownClosePct to RiskControlConfig
- Extract shouldTriggerDrawdownClose for configurable thresholds (defaults: 5% min profit, 40% pullback)
- Add unit tests for drawdown close logic
- Add enable checkbox and min profit % / pullback % inputs to RiskControlEditor
- Add RiskControlConfig fields to web types
@cla-assistant
Copy link

cla-assistant bot commented Mar 4, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant